part of '../page.dart';

class _ClockwiseSlideBuiltTransition extends StatelessWidget {
  const _ClockwiseSlideBuiltTransition({
    required this.animation,
    required this.child,
    super.key,
  });

  static const _kAngle = pi / 16;

  final Widget child;
  final Animation<double> animation;

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(
      builder: (context, constraints) {
        final width = constraints.maxWidth;
        final height = constraints.maxHeight;

        return AnimatedBuilder(
          animation: animation,
          child: child,
          builder: (context, child) {
            final dx = height * sin(_kAngle);

            final matrix = Matrix4.translationValues(
              (width + dx) * animation.value,
              0.0,
              0.0,
            );

            matrix.rotateZ(_kAngle * animation.value);

            return Transform(
              transform: matrix,
              origin: Offset(width / 2, height / 2),
              child: child,
            );
          },
        );
      },
    );
  }
}
